import Cookies from 'js-cookie';

export const ACCESS_TOKEN = 'access_token';

/**
 * 关于授权的工具类
 */
export const AuthUtils = {
	setToken(key, value) {
		window.sessionStorage.setItem(key, value);
	},
	getToken(key) {
		return window.sessionStorage.getItem(key);
	},
	checkToken(key) {
		return this.getToken(key) ? true : false;
	},
	removeToken(key) {
		window.sessionStorage.removeItem(key);
	},
	// 关于权限认证操作
	accessToken: {
		set: (value) => {
			if (!value) return;
			localStorage.setItem(ACCESS_TOKEN, value);
		},
		get: () => {
			return localStorage.getItem(ACCESS_TOKEN);
		},
		check: () => {
			const token = localStorage.getItem(ACCESS_TOKEN);
			return token ? true : false;
		},
		remove: () => {
			localStorage.removeItem(ACCESS_TOKEN);
		},
	},
};
